from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain_community.llms import Ollama
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser


def read_txt_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()
    return content

def save_to_markdown(file_path, content):
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(content)



llm = Ollama(model="qwen2.5")
prompt = ChatPromptTemplate.from_template("""
        将以下文本内容转为 Markdown 格式, 你不要总结里面的内容，保留原数据和全部内容，只需要变成markdown的格式

        文本内容：
        {content}

""")

document_chain = prompt | llm

# 根据文件内容回答问题的逻辑
result = document_chain.invoke({
    "content": read_txt_file("src/test/uploads/lol14.19版本改动.txt")
})


print(result)

save_to_markdown("./src/test/uploads/demo.md", result)